<template>
  <div v-if="pageReady" id="orderinfo">
    <el-row :gutter="16">
      <el-col :span="6">
        <el-card class="box-card">
          <div slot="header"><span style="font-size: 18px;font-weight: bold;">Order Information</span></div>
          <div class="infobody">
            <p class="title">order No:{{iraorder.orderno}}</p>
            <p class="title">order title:{{iraorder.title}}</p>
            <p class="kehu">Customer Name:{{iraorder.kehuusername}}</p>
            <p class="time">Expected Completion Date:{{iraorder.completedate}}</p>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18">
        <el-card class="box-card">
          <div slot="header"><span style="font-size: 18px;font-weight: bold;">Product Information</span></div>
          <div class="infobody">
            <table class="mytable">
              <tr>
                <th id="lineTd" style="width: 250px">
                  <span style="float:left;margin-top:20px;">product</span>
                  <span style="float:right;margin-top:-10px;">produce step</span>
                </th>
                <th v-for="(s,index) in stepList" :key="s.id">
                  {{s.stepname}}
                </th>
              </tr>
              <tr v-for="(p,index) in productStepList" :key="p.id">
                <td style="font-weight: 800;">
                  {{p.productname}}({{p.productguige}})
                </td>
                <td v-for="(step,sIndex) in p.iraOrderProductStepCountList" :key="step.id">
                  {{step.stepCount}}
                </td>
              </tr>
            </table>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="16" style="margin-top: 6px">
      <el-col :span="6" v-for="(item,index) in wlObj.list" :key="item.id + '-' + index">
        <el-card class="box-card">
          <div slot="header">
            <span style="font-size: 18px;font-weight: bold">logistics No:{{item.wuliuno}}</span>
          </div>
          <div class="divnr">logistics Name：<span>{{item.wuliuname}}</span></div>
          <div class="divnr">Transportation Company：<span>{{item.companyname}}</span></div>
          <div class="product">
            freight:
            <el-badge :value="p.shuLiang" class="badgeitem" v-for="(p,pindex) in item.productList" :key="p.id" v-if="p.shuLiang" type="success">
              <el-button size="mini">{{p.productname}}-{{p.productguige}}</el-button>
            </el-badge>
          </div>
          <div class="step">
            <div style="margin: 10px auto;">
              <el-steps :active="item.activeStep" finish-status="success" process-status="finish" direction="vertical" :space="80">
                <el-step :title="s.stepname" v-for="s in item.stepList" :key="s.id">
                  <div slot="description">
                    <div>
                      {{s.desc}}
                    </div>
                    <div v-show="s.imageToggle">
                      <ImageUpload :entityId="s.id" :entityTypeId="FileEntityType.logisticsStepImage" onlyShow :key="'ImageUpload' + s.id"></ImageUpload>
                    </div>
                  </div>
                </el-step>
              </el-steps>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-alert v-if="wlObj.list.length===0"
      title="No logistics orders" type="error" center :closable="false">
    </el-alert>
  </div>
</template>

<script>
import request from '@/utils/request'
import FileEntityType from "../../utils/FileEntityType";
import dayjs from "dayjs";
export default {
  data() {
    return {
      orderId : 0,
      iraorder : {},
      productStepList:[],
      stepList:[],

      wlsd: {
        orderId:0,
        pageNum: 1,
        pageSize: 12
      },
      wlObj: {},
      FileEntityType:FileEntityType,

      pageReady: false,
    }
  },
  mounted() {
    this.orderId= this.$route.query.orderId
    this.wlsd.orderId= this.$route.query.orderId
    this.initData();
  },
  methods: {
    async initData(){
      //order check
      const checkRes = await request({ url: '/emp/order/checkorder', data: {id : this.orderId} });
      if(checkRes.code !== '200'){
        this.$message.error('illegal access');
        return;
      }

      //order info
      const res = await request({ url: '/emp/order/getordermap', data: {id : this.orderId} });
      this.iraorder = res.data
      this.iraorder.completedate = dayjs(this.iraorder.completedate).format('YYYY-MM-DD')


      //Product info
      const res2 = await request({
        url: '/emp/orderproduct/listproductstepcount',
        data: {id : this.orderId}
      })
      const { data } = res2
      this.productStepList = data
      if(this.productStepList.length > 0){
        this.stepList = this.productStepList[0].iraOrderProductStepCountList;
      }

      const res3 = await request({
        url: '/emp/orderwuliu/pagewuliu',
        data: this.wlsd
      })
      this.wlObj = res3.data
      this.wlObj.list.forEach((wlItem) =>{
        const wlItemStep = wlItem.stepList;
        for(let i=0;i<wlItemStep.length;i++){
          if(wlItemStep[i].speed !== 100){
            wlItem.activeStep = i;
            break;
          }
        }
        for(let i=0;i<wlItemStep.length;i++){
          const speed = wlItemStep[i].speed;
          wlItemStep[i].desc = speed === 100 ? 'completed' : speed > 0 ? 'In transit:' + speed+"%" : 'not started';
          wlItemStep[i].imageToggle = true;
        }
      })

      this.pageReady = true;
    },

  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-card__header{
  padding: 8px;
}
#orderinfo .el-card{
  margin-bottom: 0 !important;
}
div.infobody{
  padding-left: 20px;
  height: 210px;
  overflow-y: auto;
  p.title{
    font-size: 16px;
    padding: 6px 0;
    margin: 0;
  }
  p.time,
  p.kehu{
    font-size: 14px;
    color: #777777;
    padding: 6px 0;
    margin: 0;
  }
  #lineTd{
    background:#FFFFFF url() no-repeat 100% center;
  }
}

div.divnr{
  text-indent: 12px;
  font-size: 14px;
  color: #666666;
  height: 30px;
  line-height: 30px;
}
div.cardfooter{
  text-align: right;
  padding-bottom: 5px;
  padding-right: 5px;
}
div.product{
  padding-left: 12px;
  margin-top: 10px;
  .badgeitem{
    margin-right: 20px;
    margin-bottom: 8px;
  }
}
div.step{
  padding-left: 12px;
  max-height: 432px;
  overflow-y: auto;
}
</style>
